﻿using Cl.Model.DataBaseEntityDtos.Goods.BaseGoods;
using Cl.Model.DataBaseEntityDtos.Orders.GoodsOrders;
using Cl.Model.Results;
using Cl.Service.Service.Goods.BaseGoods;
using Cl.Service.Service.Orders.GoodsOrders;
using Cl.WebApi.Controllers;
using Cl.WebApi.SwaggerModel;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Cl.WebApi.Areas.Customer.Orders
{
    /// <summary>
    /// 商品订单管理
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = Grouping.ClientGroup)]
    public class GoodsOrderController : BaseController
    {

        private readonly IGoodsOrderService GoodsOrderService;

        /// <summary>
        /// 构造函数
        /// </summary>
        public GoodsOrderController(IGoodsOrderService goodsOrderService)
        {
            GoodsOrderService = goodsOrderService;
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<PageResultModel<GoodsOrderOutputDto>> Get([FromQuery] SearchGoodsOrderDto request)
        {
            return GoodsOrderService.Query(request);
        }


        /// <summary>
        /// 创建订单
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        [HttpPost("CreateOrder")]
        public async Task<ResultInfoModel> CreateOrder([FromBody] GoodsOrderInputDto value)
        {
            if (value == null)
                return GetResult.Error("参数不能为null");
            var result = await GoodsOrderService.CreateOrder(value);
            return result;
        }

        /// <summary>
        /// 查找订单
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        [HttpGet("FindOrder")]
        public async Task<GoodsOrderOutputDto> FindOrder(string orderCode)
        {
            var result = await GoodsOrderService.FindOrder(orderCode);
            return result;
        }


        /// <summary>
        /// 支付订单
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        [HttpPost("PayOrder")]
        public async Task<ResultInfoModel> PayOrder(PayOrderInputDto value)
        {
            var result = await GoodsOrderService.PayOrder(value);
            return result;
        }
       



    }
}
